# coding=utf-8
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User

# Create your models here.

class Post(models.Model):
	class Meta:
		verbose_name = u'文章'
		verbose_name_plural = u'文章'

	author = models.ForeignKey(User)
	title = models.CharField(max_length=200)
	text = models.TextField()
	#tags = models.ManyToManyField(Tag)
	#category = models.ForeignKey(Category)
	created_date = models.DateTimeField(default=timezone.now)
	published_date = models.DateTimeField(blank=True,null=True)	

	def publish(self):
		self.published_date = timezone.now()
		self.save()

	def get_absolute_url(self):
		from django.core.urlresolvers import reverse
		return reverse('post_detail', args=[str(self.id)])

	def __str__(self):
		return self.title	
	